package com.icode.jersey.service;

import com.icode.jersey.model.UserDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: alexz
 * Date: 14-7-11
 * Time: 上午10:54
 * To change this template use File | Settings | File Templates.
 */
public class UserServiceImpl implements UserService {
    private static List<UserDTO> userDTOs = new ArrayList<>();

    static {
        userDTOs.add(new UserDTO("ZhongGang", "zhongzhong"));
        userDTOs.add(new UserDTO("XiaYuQiong", "xiaxia"));
        userDTOs.add(new UserDTO("ZhongLingLi", "lili"));
    }

    @Override
    public UserDTO loadUserDTOByUsername(String username) {
        for (UserDTO userDTO : userDTOs) {
            if (userDTO.getUsername().equals(username)) {
                return userDTO;
            }
        }
        return null;
    }

    @Override
    public List<UserDTO> loadUserDTOs() {
        return userDTOs;
    }

    @Override
    public UserDTO createUser(String username, String password) {
        UserDTO userDTO = new UserDTO(username, password);
        userDTOs.add(userDTO);
        return userDTO;
    }
}
